<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基于WebServer的数据采集和控制</title>
    <style>
        input {
            text-align: center;
        }
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-image: url("./R-C.jfif");
            background-position: center;
            background-size: cover;
        }

        .container {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            width: 800px;
            text-align: center;
            opacity: 95%;
        }

        h1 {
            color: #333;
        }

        input[type="text"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        input[type="button"],
        input[type="radio"] {
            margin: 5px;
            cursor: pointer;
        }

        input[type="button"] {
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 4px;
            padding: 10px 15px;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        input[type="button"]:hover {
            background-color: #0056b3;
        }

        input[type="radio"] {
            margin: 0 5px;
        }

        textarea {
            width: 95%;
            height: 200px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            resize: vertical;
            font-size: 18px;
        }

        label {
            margin: 0 10px;
        }
    </style>
    <script>

        function get_data() {
            var data = "get";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(data);
            xhr.onload = function () {
                var met = xhr.responseText;
                var values = met.split(' ');
                document.getElementById("t").value = values[0];
                document.getElementById("h").value = values[1];
            }
        }

        function history() {
            var data = "history";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(data);
            xhr.onload = function () {
                var met = xhr.responseText;
                document.getElementById("his").value = met;
            }
        }

        function del() {
            var data = "del";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(data);
        }

        function led1() {
            var led = "led 1";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(led);
        }
        function led0() {
            var led = "led 0";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(led);
        }

        function beep1() {
            var beep = "beep 1";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(beep);
        }

        function beep0() {
            var beep = "beep 0";
            var xhr = new XMLHttpRequest();
            var url = "";
            xhr.open("post", url, true);
            xhr.send(beep);
        }
    </script>
</head>

<body>
    <div class="container">
        <h1>基于WebServer的数据采集和控制</h1>
        <div>
            <label for="t">温度:</label>
            <input type="text" id="t" readonly>
        </div>
        <div>
            <label for="h">湿度:</label>
            <input type="text" id="h" readonly>
        </div>
        <input type="button" value="获取温度湿度" onclick="get_data()">
        <br>
        <div>
            <span>LED:</span>
            <label>
                <input type="radio" name="LED" onclick="led1()"> 开
            </label>
            <label>
                <input type="radio" name="LED" onclick="led0()" checked="checked"> 关
            </label>
        </div>
        <div>
            <span>BEEP:</span>
            <label>
                <input type="radio" name="BEEP" onclick="beep1()"> 开
            </label>
            <label>
                <input type="radio" name="BEEP" onclick="beep0()" checked="checked"> 关
            </label>
        </div>
        <br>
        <input type="button" value="获取历史记录" onclick="history()">
        <input type="button" value="清空历史记录" onclick="del()">
        <br>
        <textarea id="his" readonly ></textarea>
    </div>
</body>

</html>